// 3. 多态
#include <iostream>
using namespace std;

// 基类
class Animal {
public:
    virtual void makeSound() {
        cout << "Animal sound" << endl;
    }
};

// 派生类
class Dog : public Animal {
public:
    void makeSound() override {
        cout << "Woof!" << endl;
    }
};

// 派生类
class Cat : public Animal {
public:
    void makeSound() override {
        cout << "Meow!" << endl;
    }
};

int main() {
    Animal* myAnimal;

    Dog myDog;
    Cat myCat;

    myAnimal = &myDog;
    myAnimal->makeSound();  // 输出: Woof!

    myAnimal = &myCat;
    myAnimal->makeSound();  // 输出: Meow!

    return 0;
}
